package cn.com.gridinfo.sooc.core.my.personal.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.inputmethod.EditorInfo;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.jeremy.arad.utils.AnimUtil;
import com.jeremy.arad.utils.StringUtils;

import butterknife.ButterKnife;
import butterknife.InjectView;
import butterknife.OnClick;
import cn.com.gridinfo.sooc.R;
import cn.com.gridinfo.sooc.base.BaseSoocActivity;

/**
 * 已绑定的邮箱
 * Created by liuxiaochen on 2015/12/21.
 */
public class OnBoundEmailActivity extends BaseSoocActivity {
    @InjectView(R.id.email_address)//已绑定的邮箱地址
    TextView emailAddress;
    @InjectView(R.id.btn_next)//下一步按钮
    Button btnNext;
    private String email;
    private String newEmail;
    public static OnBoundEmailActivity instance;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.my_onbound_email);
        ButterKnife.inject(this);
        instance = this;
        email=getIntent().getStringExtra("emailAddress");//拿到上个界面传来的邮箱地址
        initView();//初始化数据
        emailAddress.setImeOptions(EditorInfo.IME_ACTION_NEXT);
        emailAddress.setOnEditorActionListener(new TextView.OnEditorActionListener() {
            @Override
            public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
                if (actionId == EditorInfo.IME_ACTION_NEXT) {
                    if (validateNotNull()) {
                        next();
                    }

                }
                return false;
            }
        });
    }
    private boolean validateNotNull(){
        //账号为空
        if(StringUtils.isNull(emailAddress.getText().toString().trim())){
            emailAddress.requestFocus();
            return false;
        }
        return true;
    }
    //初始化显示绑定的邮箱
    private void initView() {
//            String beforeEmail = email.substring(0, 2);//拿到邮箱地址的前两位
//            String emailTyp = email.substring(email.indexOf("@") + 1, email.indexOf(".com"));//拿到邮箱类型
//            newEmail = beforeEmail + "****@" + emailTyp + ".com";
            emailAddress.setText(email);
    }
    //设置标题
    @Override
    public String setupToolBarTitle() {
        return "绑定邮箱";
    }
    //设置左边按钮
    @Override
    public boolean setupToolBarLeftButton(ImageView leftButton) {
        return true;
    }
    //返回
    @OnClick(R.id.toolbar_leftbtn)
    void onGoBack() {
        finish();
    }
    //点击 下一个
    @OnClick(R.id.btn_next)
    void next(){
        startActivity(new Intent(this, ChangeEmailActivity.class));
        AnimUtil.intentSlidIn(this);
    }
}
